import Book.BookList;
import User.Admin;
import User.NormalUser;
import User.User;

import java.util.Scanner;

public class TestMain {

    public static User login() {//登录
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = scanner.nextLine();
        System.out.println("请输入你的身份:1-->管理员，2-->普通用户");
        int choice = scanner.nextInt();

        if (choice == 1) {//向上转型
            return new Admin(name);
        } else {
            return new NormalUser(name);
        }

    }

    public static void main(String[] args) {
        //1.准备书籍
        BookList bookList = new BookList();
        //2.登录
        User user = login();//user根据login方法中的choice选择可能是Admin或者NormalUser.
        while (true) {
            int choice = user.menu();//这里重写了menu方法，发生运行时绑定
            //选择是几，就可以对应哪个方法了
            user.doOperation(bookList, choice);
        }
    }
}
